package com.kolon.business.mCafeteriaMenu.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.framework.constant.Constant;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;
import com.kolon.framework.util.MsgUtil;

@Controller("com.kolon.business.mCafeteriaMenu.controller.mCafeteriaBoardWriteController")
public class mCafeteriaBoardWriteController implements SimpleController {

	@RequestMapping("/business/mCafeteriaMenu/mCafeteriaBoardWrite.do")
	public ModelAndView controller(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// 도메인
		String url = MsgUtil.getMessage("xml.url");
		// 세션 아이디 및 암호 값을 불러옴
		HttpSession httpSession = request.getSession();
		Map userMap = (Map)httpSession.getAttribute(Constant.SESSION_USER_INFO);
		String id = (String)userMap.get("userId");
		String pw = (String)userMap.get("userPw");
		String res = request.getParameter("res");         //구내식당 코드
		String inEmoID = request.getParameter("inEmoID"); //이모티콘 번호
		String YMD = request.getParameter("YMD");         //연도
		if(inEmoID == null) inEmoID ="1";
		String returnUrl = "/business/mCafeteriaMenu/mCafeteriaBoard.do?YMD="+YMD +"&res="+res; //등록후 Url		
		ModelAndView modelAndView = new ModelAndView();
		if(!"".equals(request.getParameter("inOpinion")) && request.getParameter("inOpinion")!=null ) {
			StringBuffer buffer = new StringBuffer();
			buffer.append(url);			
			buffer.append("/cafeteria_menu.aspx?Gubun=").append("RestOpinionWrite");
			buffer.append("&inCafeCD=").append(res);
			buffer.append("&inEmoID=").append(inEmoID);
			buffer.append("&inYMD=").append(YMD);
			buffer.append("&inOpinion=").append(ComUtil.getEncode(request.getParameter("inOpinion"),"EUC-KR"));
			buffer.append("&userid=").append(id);
			// XML DOCUMENT 및 인증 처리
			ComUtil.getDocument(buffer.toString(), id, pw);
			modelAndView.addObject("scriptType", "009");
			modelAndView.addObject("message_url", returnUrl);
			modelAndView.setViewName("/business/common/alert");
		}
		modelAndView.addObject("YMD", YMD);
		modelAndView.addObject("res", res);
		return modelAndView;
	}

}